<template>
  <div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>


    <el-table :data="carList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="车辆编号" prop="vehiclesNum" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="车辆VIN" prop="vin" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="车辆类型" prop="typeName" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="车辆品牌" prop="brandName" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="电子围栏" prop="fenceId" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="车辆状态" prop="status" :show-overflow-tooltip="true" width="120">
        <template slot-scope="scope">
          <el-tag type="success" v-show="scope.row.status==1">空闲</el-tag>
          <el-tag type="danger" v-show="scope.row.status==2">出租中</el-tag>
        </template>
      </el-table-column>>
      <el-table-column label="电机厂商" prop="motorName" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="电机编号" prop="motorNum" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="电池厂商" prop="batteryName" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="电池编号" prop="batteryNum" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog  :title="title" :visible.sync="open">
      <el-form :model="form">
        <el-form-item label="车辆编号" :label-width="formLabelWidth">
          <el-input v-model="form.vehiclesNum" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="车辆vin" :label-width="formLabelWidth">
          <el-input v-model="form.vin" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="车辆类型" :label-width="formLabelWidth">
          <el-select v-model="form.type" placeholder="请选择">
            <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆品牌" :label-width="formLabelWidth">
          <el-select v-model="form.brand" placeholder="请选择">
            <el-option
                v-for="dict in brandOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电子围栏" :label-width="formLabelWidth">
          <el-input v-model="form.electronicFence" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电机编号" :label-width="formLabelWidth">
          <el-input v-model="form.motorNum" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电机厂商" :label-width="formLabelWidth">
          <el-select v-model="form.motorManufacturers" placeholder="请选择">
            <el-option
                v-for="dict in motorOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电池编号" :label-width="formLabelWidth">
          <el-input v-model="form.batteryNum" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电池厂商" :label-width="formLabelWidth">
          <el-select v-model="form.batteryManufacturers" placeholder="请选择">
            <el-option
                v-for="dict in batteryOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆状态" :label-width="formLabelWidth">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option  value="1" label="正常"></el-option>
            <el-option  value="2" label="异常"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
export default {
  name: "CarView",
  data() {
    return {
      carList:[],
      ids:[],
      form:{},
      typeOptions:[],
      brandOptions:[],
      batteryOptions:[],
      motorOptions:[],
      title:"",
      open:false,
      formLabelWidth:'120px'

    }
  },
  created() {

  },
  methods: {
    //选择框
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.vehiclesId)
    },
    handleAdd(){
      this.form={}
      this.open=true
      this.title = "添加角色";
    },
    // 添加修改按钮
    submitForm: function() {
      if (this.form.vehiclesId != undefined) {
        this.axios.post("").then(()=>{

        })
      } else {
        this.axios.post("http://localhost:10018/car/saveCar",this.form).then(()=>{
          this.$message.success("添加成功");
          this.open = false;
          this.getCarList();
        })
      }
    },
    //修改
    handleUpdate(){

    },
    //删除
    handleDelete(row){
      const vehiclesIds = row.vehiclesId || this.ids;
      this.axios.delete("http://localhost:10018/car/"+vehiclesIds).then(()=>{
        this.$message.success("删除成功");
        this.getCarList();
      })
    },
    resetQuery(){

    },

  }
}
</script>

<style scoped>

</style>
